package com.lwlk.util.functional;

public class Common {
    public static <T> T identity(final T x) {
        return x;
    }
    public static <T> T returnThat(final Action0 action, final T that) {
        action.call(); return that;
    }
    public static <T> void let(final T that, final Action1<T> action) {
        action.call(that);
    }
    public static <T> void letWhen(final T that, final Method1<Boolean, T> condition, Action1<T> action) {
        if(condition.call(that)) action.call(that);
    }
    public static <T> void letIf(final T that, final Method1<Boolean ,T> condition, Action1<T> trueAction, Action1<T> falseAction) {
        if(condition.call(that)) trueAction.call(that); else falseAction.call(that);
    }
    public static <T, R> R decorate(final T that, final Method1<R, T> method) {
        return method.call(that);
    }
}
